<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品列表</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script src="${Plugins}/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${BasePath}/res/plugins/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>

<style type="text/css">
#searchbar{
   margin-bottom: 10px;
   margin-left:15px;
  }
  .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
.l-button-search {
	width: 130px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}
.l-button-reset {
	width: 50px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}
</style>
</head>

<body style="padding:6px; overflow:hidden;">
<div class="navbar">
		<span>您当前的位置：商品管理 &gt</span>
		库存异动出入库同步
</div><br><br>
<form action="syncInOutRecord.do"  name="queryForm" id="queryForm" method="POST">
		同步时间段：<input id="startGrabTime" type="text" name="startGrabTime" readonly="readonly" value="${startGrabTime }" class="Wdate" value="" size="21"
    	onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,maxDate:'#F{$dp.$D(\'endGrabTime\')||\'2020-10-01\'}'})" >~
    	<input id="endGrabTime" type="text" name="endGrabTime" readonly="readonly" value="${endGrabTime }" class="Wdate" value="" size="21"
    	onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,minDate:'#F{$dp.$D(\'startGrabTime\')||\'2013-01-01\'}'})" >&nbsp;&nbsp;&nbsp;&nbsp;<br><br><br>
		<input type="button" value="库存异动出入库同步" class="l-button-search" onclick="javascript:manualAdd();">&nbsp;&nbsp;&nbsp;&nbsp;<input  type="button" id="resetButton" value="重置" class="l-button-reset" >
	</form><br>
<div id="maingrid" style="margin:0; padding:0"></div>
  <div style="display:none;">
  <!-- 展示列表数据  -->
</div><br><br>

	<script>
	//var grid = null;
	//var icsJson = ${icsJson};
	//var icsSize = ${icsSize};
    //var icsJsonData = {"Rows": icsJson, "Total": icsSize};
    $(function () {
    	$('#resetButton').click(function() {
        	$('#startGrabTime').val('');
        	$('#endGrabTime').val('');
        });
    	/* grid = $("#maingrid").ligerGrid({
            columns: [
            { display: '仓库编码', name: 'warehouseCode',align: 'left', width: '8%' },
            { display: '单号', name: 'orderNo', width: '12%' },
            { display: '模块编码', name: 'moduleCode', width: '10%', render: function(rowdata, rowindex, value) {
            	var text = '';
            	if (rowdata.moduleCode == '0001') {
            		text = '其他入库';
            	} else if (rowdata.moduleCode == '0002') {
            		text = '其他出库';
            	} else if (rowdata.moduleCode == '0003') {
            		text = '采购入库';
            	} else if (rowdata.moduleCode == '0004') {
            		text = '库内盘点';
            	} else if (rowdata.moduleCode == '0005') {
            		text = '调拨入库';
            	} else if (rowdata.moduleCode == '0006') {
            		text = '调拨出库';
            	} else if (rowdata.moduleCode == '0007') {
            		text = '配货单出库';
            	} else if (rowdata.moduleCode == '0008') {
            		text = '销售退货入库';
            	} else if (rowdata.moduleCode == '0009') {
            		text = '采购退货出库';
            	}
            	return text;
            } },
            { display: '货品编号', name: 'sku', width:'10%' },
            { display: '数量', name: 'qty',align: 'left', width:'10%' },
            { display: '审核人', name: 'auditor',align: 'left', width:'10%' },
            { display: '审核时间', name: 'auditTime', width:'12%' },
            { display: '备注', name: 'remark', width:'10%' }
            ], 
            pageSize:30,
            width: '100%',
            height: '100%',
            toolbar: { items: [
          		{ text: "手动同步", click: manualAdd, icon: "add"},
            ]},
    		data: $.extend(true,{},icsJsonData)
        });
    	$form1 = $("#queryForm");
    	$form1.submit(function() {
    		if ($('#startGrabTime').val() == '' || $('#endGrabTime').val() == '') {
    			$.ligerDialog.warn('抓取时间都不能为空');
    			return false;
    		}
    		var sGrabTime = $('#startGrabTime').val().replace("-","/").replace("-","/");
    		var eGrabTime = $('#endGrabTime').val().replace("-","/").replace("-","/");
    		var intervalTime = new Date(eGrabTime).getTime() - new Date(sGrabTime).getTime();
    		var twoDateTime = 85 * 60 * 1000;
    		if ((intervalTime - twoDateTime) > 0) {
    			$.ligerDialog.warn('抓取时间只能相隔85分钟');
    			return false;
    		}
    	}); */
    	
    	var v = $("form").validate({
					submitHandler : function() {
						var options = {
							type : 'POST',
							beforeSend : function() {
								$("#queryForm").find(":submit,:button").attr(
										"disabled", true);
								$.ligerDialog.waitting('正在同步中,请稍候...');
							},
							success : function(data) {
								$.ligerDialog.closeWaitting();
								if (data == "success") {
									//同步成功
									$.ligerDialog.alert("同步成功");
								} else if(data == "noData") {
									$.ligerDialog.alert("没有要同步的数据");
								} else {
									//同步失败
									$.ligerDialog.alert("同步失败");
								}
								$("#queryForm").find(":submit,:button")
										.removeAttr("disabled");

							},
							error : function() {
								$.ligerDialog.alert('请求异常');
							}
						}, $form1 = $("#queryForm");
						$form1.ajaxSubmit(options);
						return false;
					}
				});

   	});
	function manualAdd() {
		/* if (icsSize == 0) {
			alert("无同步数据");
			return;
		} */
		if ($('#startGrabTime').val() == '' || $('#endGrabTime').val() == '') {
			$.ligerDialog.warn('同步时间都不能为空');
			return;
		}
		var sGrabTime = $('#startGrabTime').val().replace("-","/").replace("-","/") + " 00:00:00";
		var eGrabTime = $('#endGrabTime').val().replace("-","/").replace("-","/") + " 00:00:00";
		var intervalTime = new Date(eGrabTime).getTime() - new Date(sGrabTime).getTime();
		var twoDateTime = 2 * 24 * 60 * 60 * 1000;
		if ((intervalTime - twoDateTime) > 0) {
			$.ligerDialog.warn('同步时间只能相隔2天');
			return;
		}
		$.ligerDialog.confirm('确定手动同步', function(yes) {
			if (yes) {
				$('#queryForm').submit();
				/* $.post("addInventoryChangeManully.do", function(data) {
					if (data == "success") {
						alert("同步成功");
						//window.location.reload();
					} else {
						alert("同步失败" + data);
						//window.location.reload();
					}
				}); */
			}
		});
	}
    </script>
</body>
</html>